<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    (function () {
        function Obse() {
            this.obj = {}
            //订阅消息
            this.on = function (type, handler) {
                this.obj[type] = this.obj[type] ? this.obj[type] : []
                this.obj[type].push(handler)
            }
            //发布消息
            this.emit = function (type, mm) {
                if (this.obj[type]) {
                    this.obj[type]
                    this.obj[type].forEach((item) => {
                        item(mm)
                    })
                }
            }
        }

        window.Obse = Obse
    })()
    var ss = new Obse()
    //订阅消息   
    ss.on('lili', function (mm) { 
        console.log('丽收到了lili的消息；' + mm); })
    ss.on('lili', function (mm) {
        console.log('莉莉收到了lili的消息；'+mm);
     })
    ss.on('lili', function (mm) {
        console.log('丽丽收到了lili的消息；' + mm);
    })
    ss.on('lili', function (mm) {
        console.log('李丽收到了lili的消息；'+mm);
     })
    ss.on('llll', function (mm) {
        console.log('李娜 收到了来自llll的消息:' + mm);
    })
    ss.on('llll', function (mm) {
        console.log('丽娜 收到了来自llll的消息:' + mm);
     })
    ss.on('llll', function (mm) {
        console.log('lllll 收到了来自llll的消息:' + mm);
    })
    console.log(ss);


    //发布消息
    ss.emit('llll', '今天星期天')
    ss.emit('lili', '今天双11')
</script>